import {
	defineConfig
} from 'vite'
import vue from '@vitejs/plugin-vue'
import {
	resolve
} from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
	ElementPlusResolver
} from 'unplugin-vue-components/resolvers'
import postcssPxtorem from 'postcss-pxtorem'

// https://vitejs.dev/config/
export default defineConfig({
	base: './',
	plugins: [
		vue(),
		AutoImport({
			resolvers: [ElementPlusResolver()]
		}),
		Components({
			resolvers: [ElementPlusResolver()]
		})
	],
	//rem配置
	css: {
			postcss: {
				plugins: [
					postcssPxtorem({
							rootValue: 192, //根元素字体大小
							propList: ['*'], //可以从px转换为rem的属性，匹配正则
							// unitPrecision:5, //允许rem单位增长的十进制数字
							// replace:true, //替换包含rems的规则，而不添加后备
							// mediaQuery:false, //允许在媒体查询中转换px
							// minPixelValue:0, //设置要替换的最小像素值
							// selectorBlackList:[], //忽略转换正则匹配项
							exclude:/node_modules/i  //要忽略并保留为px的文件路径
					})
				]
			}
	},
	server: {
		proxy: {
			'/app': {
				target: 'http://kejixiaoyuan.haimijiaoyu.com/',
				changeOrigin: true, 
				secure: true,
				rewrite: path => {
					console.log('-----1', path.replace(/^\/app/,''))
					return path.replace(/^\/app/,'')
				}
			},
		},
	},
	resolve: {
		alias: {
			'@': resolve('src')
		}
	}
})